/* 表单 */
var Service_Repwd = new MVVM.Service({
	pretreatment: function(data, option) {
		return JSON.stringify(data);
	},
	dosuccess: function(data, option) {
		return data;
	},
	doerror: function(e, err, option) {
		return e;
	},
	validate: function(data, option) {
		if(parseInt(data.code) === 0)
			return 0;
		else
			return data;
	},
	ajaxCall: function(data, option) {
		var self = this;
		appcan.request.ajax({
			url: server_path + "/user/updatePassword",
			type: "POST",
			data: this.pretreatment(data, option),
			dataType: "json",
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				var res = self.validate(data, option);
				if(!res) {
					option.success(self.dosuccess(data.result, option));
				} else
					option.error(self.doerror(data, res, option));
			},
			error: function(e, err) {
				option.error(self.doerror(e, err, option));
			}
		});
	}
});

var Model_Repwd = new(MVVM.Model.extend({
	defaults: {

	},
	initialize: function() {
		return;
	},
	parse: function(data) {
		return data;
	},
	validate: function(attrs, options) { //提交之前的校验
		if(attrs == "") {
			return "";
		}
		return;
	},
	computeds: {},
	sync: function(method, model, options) {
		switch(method) {
			case "create":
				Service_Repwd.request(this.toJSON(), options);
				break;
			case "update":
				break;
			case "patch":
				break;
			default:
				break;
		}
	},
}))()

var ViewModel_Repwd = new(MVVM.ViewModel.extend({
	el: "body",
	events: {},
	initialize: function() {},
	model: Model_Repwd,
	saveModel: function(param) {
		var self = this;

		var data = param.data;
		this.model.set(data);
		if(!this.model.isValid(data)) {
			appcan.window.openToast(this.model.validationError, 2000);
			return;
		}
		this.model.save(data, {
			success: function(cols, resp, options) {
				utils.handleNoDataShow(resp, null, true);
				showLoadingStatus();
				param.callback && param.callback();
			},
			error: function(cols, error, options) {
				global_error(error, true);
			}
		});
	}
}))();

